import { createApp, VNode } from 'vue';
import './style.css';

const apps = import.meta.webpackContext('./views', {
  recursive: true,
  regExp: /\.vue$/,
});

const bootstrap = async (com: VNode, target: string) => {
  const app = createApp(com);

  app.config.performance = true;
  app.mount(target);
};

function extractName(filePath: string) {
  const match = filePath.match(/\.\/(.+?)\.vue$/);
  return match ? match[1] : null;
}

const name = location.pathname.replace(/^\//, '') || 'App';

apps.keys().forEach((key) => {
  const app = extractName(key);
  if (app === name) {
    bootstrap((apps(key) as any).default, '#root');
  }
});
